<?php
/**
 * @package		Joomla.Administrator
 * @subpackage	com_weblinks
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('JPATH_BASE') or die;

/**
 * Supports an HTML select list of provinces
 *
 * @package		Joomla.Administrator
 * @subpackage	com_weblinks
 * @since		1.6
 */
class JFormFieldLanguageOption extends JFormField
{
	/**
	 * The form field type.
	 *
	 * @var		string
	 * @since	1.6
	 */
	protected $type = 'LanguageOption';

	/**
	 * Method to get the field input markup.
	 *
	 * @return	string	The field input markup.
	 * @since	1.6
	 */
	protected function getInput()
	{
		// Initialize variables.
		$db = JFactory :: getDBO();
		$html = array();
		$attr = '';
		

		// Initialize some field attributes.
		$class = $this->element['class'] ? ' class="'.(string) $this->element['class'].'"' : '';
		$size = $this->element['size'] ? ' size="'.(int) $this->element['size'].'"' : '';

		// Initialize JavaScript field attributes.
		$attr .= $this->element['onchange'] ? ' onchange="'.(string) $this->element['onchange'].'"' : '';

		// Get some field values from the form.
		$username	= (string) JRequest::getCmd('username');
		
		//Get p_id from c_id if provided
		
		
		// Build the query for the ordering list.
		$query = "SELECT u.username, u.name FROM #__users u LEFT JOIN #__congregation_profile m ON u.username = m.username WHERE m.username IS NULL OR u.username='" . $this->value . "'";

		// Create a read-only list (no name) with a hidden input to store the value.
		$db->setQuery($query);
		$result = $db->loadObjectList();
		$options = array();
		$options[] = JHTML::_('select.option', '', JText::_('Select a language'));
		$options[] = JHTML::_('select.option', 'it', JText::_('Italiano'));
		$options[] = JHTML::_('select.option', 'pt', JText::_('Portuguese'));
		$options[] = JHTML::_('select.option', 'es', JText::_('Spagnolo'));
		$options[] = JHTML::_('select.option', 'en', JText::_('Inglese'));
		$options[] = JHTML::_('select.option', 'fr', JText::_('Francese'));

		foreach($result as $row)
		{
			$options[] = JHTML::_('select.option', $row->username, $row->name);
		}
		$dropdown = JHTML::_('select.genericlist', $options, $this->name, $class, 'value', 'text', $this->value);
		return $dropdown; 
		
	}
}
